using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace jSLCore.Service.Data
{
    public static class TypeSerialization
    {
        public static object ToObject(this byte[] array)
        {
            var stream = new MemoryStream(array);
            var formatter = new BinaryFormatter();

            var res = formatter.Deserialize(stream);
            stream.Close();
            return stream;

        }

        public static byte[] ToByteArray(this object value)
        {
            var formatter = new BinaryFormatter();
            var stream = new MemoryStream();
            formatter.Serialize(stream, value);

            var res = stream.ToArray();
            stream.Close();
            return res;
        }
    }
}